home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0038_Detect Keys DOWN.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  1KB  |  67 lines

  1. { INGO ROHLOFF
  2.  
  3. > I've got a problem I just CAN'T solve...
  4. > In a PASCAL-program I want to execute a procedure every time the user
  5. > presses a key... Fairly easy, right ? But here comes the problem : I want
  6. > to repeat that procedure until he RELEASES that key...
  7.  
  8. The only way to do that is to hook up the int 9 (the Keyoard Int...).
  9. }
  10.  
  11. Program KEY;
  12.  
  13. uses
  14.   crt, dos;
  15.  
  16. var
  17.   oldint  : pointer;
  18.   keydown : byte;
  19.   keys    : array [0..127] of boolean;
  20.   scan,
  21.   lastkey : byte;
  22.  
  23. procedure init;
  24. var
  25.   i : byte;
  26. begin
  27.   clrscr;
  28.   for i := 0 to 127 do
  29.     keys[i] := false;   {No keys pressed}
  30.   keydown := 0;
  31. end;
  32.  
  33. procedure INT9; interrupt;
  34. begin
  35.   scan := port[$60];     { Get Scancode }
  36.   if scan > $7F then     { Key released ? }
  37.   begin
  38.     if keys[scan xor $80] then
  39.       dec(keydown);
  40.     keys[scan xor $80] := false;   {Yes !}
  41.   end
  42.   else
  43.   begin
  44.     if not keys[scan] then
  45.       inc(keydown);
  46.     keys[scan] := true;  {NO ! Key pressed }
  47.     lastkey := scan;
  48.   end;
  49.   port[$20] := $20;  { Send EndOfInterrupt to Interruptcontroller }
  50. end;
  51.  
  52. begin
  53.   init;
  54.   getintvec(9, oldint);
  55.   setintvec(9, @INT9);
  56.   repeat
  57.     if (keydown > 0) and not keys[1] then
  58.     begin
  59.       repeat
  60.         sound(lastkey * 30);
  61.       until keydown = 0;
  62.       nosound;
  63.     end;
  64.   until keys[1];        {*** Wait for ESC pressed ***}
  65.   setintvec(9, oldint);
  66. end.
  67.